#include <bits/stdc++.h>
using namespace std;

int main(void)
{
    int a[110][110] = {0};
    int b[110][110] = {0};
    char str[110] = {0};
    int n, m;
    int isA = 1;
    int isB = 0;
    scanf("%d %d", &n, &m);
    int lenIa = n;
    int lenJa = m;
    int lenIb = m;
    int lenJb = n;
    for (int i = 0; i < lenIa; i++)
    {
        for (int j = 0; j < lenJa; j++)
        {
            scanf("%d", &a[i][j]);
        }
    }
    scanf(" %s", str);
    int indexS = 0;
    while (str[indexS] != '\0')
    {
        if (str[indexS] == 'A')
        {
            int indexI = 0;
            int IndexJ = 0;
            if (isA)
            {
                for (int j = 0; j < lenJa; j++)
                {
                    for (int i = lenIa - 1; i >= 0; i--)
                    {
                        b[indexI][IndexJ++] = a[i][j];
                        if (IndexJ == lenJb)
                        {
                            indexI++;
                            IndexJ = 0;
                        }
                    }
                }
                isA = 0;
                isB = 1;
            }
            else
            {
                for (int j = 0; j < lenJb; j++)
                {
                    for (int i = lenIb - 1; i >= 0; i--)
                    {
                        a[indexI][IndexJ++] = b[i][j];
                        if (IndexJ == lenJa)
                        {
                            indexI++;
                            IndexJ = 0;
                        }
                    }
                }
                isA = 1;
                isB = 0;
            }
        }
        else if (str[indexS] == 'B')
        {
            int indexI = 0;
            int IndexJ = 0;
            if (isA)
            {
                for (int j = lenJa - 1; j >= 0; j--)
                {
                    for (int i = 0; i <=lenIa - 1; i++)
                    {
                        b[indexI][IndexJ++] = a[i][j];
                        if (IndexJ == lenJb)
                        {
                            indexI++;
                            IndexJ = 0;
                        }
                    }
                }
                isA = 0;
                isB = 1;
            }
            else
            {
                for (int j = lenJb - 1; j >= 0; j--)
                {
                    for (int i = 0; i <= lenIb - 1; i++)
                    {
                        a[indexI][IndexJ++] = b[i][j];
                        if (IndexJ == lenJa)
                        {
                            indexI++;
                            IndexJ = 0;
                        }
                    }
                }
                isA = 1;
                isB = 0;
            }
        }
        else if (str[indexS] == 'C')
        {
            if (isA)
            {
                for (int i = 0; i < lenIa; i++)
                {
                    for (int j = 0; j < lenJa / 2; j++)
                    {
                        int tmp = a[i][j];
                        a[i][j] = a[i][lenJa - 1 - j];
                        a[i][lenJa - 1 - j] = tmp;
                    }
                }
            }
            else
            {
                for (int i = 0; i < lenIb; i++)
                {
                    for (int j = 0; j < lenJb / 2; j++)
                    {
                        int tmp = b[i][j];
                        b[i][j] = b[i][lenJb - 1 - j];
                        b[i][lenJb - 1 - j] = tmp;
                    }
                }
            }
        }
        else
        {
            if (isA)
            {
                for (int j = 0; j < lenJa; j++)
                {
                    for (int i = 0; i < lenIa / 2; i++)
                    {
                        int tmp = a[i][j];
                        a[i][j] = a[lenIa - 1 - i][j];
                        a[lenIa - 1 - i][j] = tmp;
                    }
                }
            }
            else
            {
                for (int j = 0; j < lenJb; j++)
                {
                    for (int i = 0; i < lenIb / 2; i++)
                    {
                        int tmp = b[i][j];
                        b[i][j] = b[lenIb - 1 - i][j];
                        b[lenIb - 1 - i][j] = tmp;
                    }
                }
            }
        }
        indexS++;
    }
    if (isA)
    {
        for (int i = 0; i < lenIa; i++)
        {
            for (int j = 0; j < lenJa; j++)
            {
                printf("%d ", a[i][j]);
            }
            printf("\n");
        }
    }
    else
    {
        for (int i = 0; i < lenIb; i++)
        {
            for (int j = 0; j < lenJb; j++)
            {
                printf("%d ", b[i][j]);
            }
            printf("\n");
        }
    }
}